<?php 
class Comments_model extends Model{

	function __construct (){
		parent::__construct();
	}

	public function GetCommentsPhoto($Idphoto){
		$sql = "SELECT * FROM `photocomments` p INNER JOIN `users` u ON u.Id = p.UserId WHERE p.Id = :IdPhoto";
		$data = array(
			"IdPhoto"	=> $Idphoto
		);

		return $this->db->select($sql,$data);
	}

	public function GetCommentsAlbum(){
		$sql = "SELECT * FROM `albumcomments` a INNER JOIN `users` u ON u.Id = a.UserId WHERE p.Id = :IdAlbum";
		$data = array(
			"IdAlbum"	=> $_POST['IdAlbum']
		);

		return $this->db->select($sql,$data);
	}

	public function newPhotoComments(){
		$date = new DateTime();
		$timestamp = $date->getTimestamp();
		$data = array(
			'Comment' 	=>  $_POST['Comment'],
			'role' 		=>  $_POST['role'],
			'Time' 		=>  $timestamp,
			'UserId' 	=>  $_SESSION['id'],
			'IdPhoto'	=> 	$_POST['IdPhoto']
		);
		$this->db->insert('photocomments', $data);
	} 

	public function editPhotoComments(){
		$date = new DateTime();
		$timestamp = $date->getTimestamp();
		$data = array(
			'Comment' 	=>  $_POST['Comment'],
			'role' 		=>  $_POST['role'],
			'EditTime' 	=>  $timestamp
		);
		$this->db->insert('photocomments', $data,'Id = '. $_POST['IdPhoto']);
	} 

	public function newAlbumComments(){
		$date = new DateTime();
		$timestamp = $date->getTimestamp();
		$data = array(
			'Comment' 	=>  $_POST['Comment'],
			'role' 		=>  $_POST['role'],
			'Time' 		=>  $timestamp,
			'UserId' 	=>  $_SESSION['id'],
			'IdAlbum'	=> 	$_POST['IdAlbum']
		);
		$this->db->insert('albumcomments', $data);
	} 

	public function editAlbumomments(){
		$date = new DateTime();
		$timestamp = $date->getTimestamp();
		$data = array(
			'Comment' 	=>  $_POST['Comment'],
			'role' 		=>  $_POST['role'],
			'EditTime' 	=>  $timestamp
		);
		$this->db->insert('albumcomments', $data,'Id = '. $_POST['IdConmment']);
	} 
}
?>